/** @format */

// YW5mQitWbmExdGlIbnRWQTNsMjlVS1Q2V1dselBLRThmZnNDV3JwU2hOM0ZVQ3ZVSlgyNzZmaWtvMXRyTEs2Vg%3D%3D

import * as aesUtil from './aesUtil'

const key = '之前约定的密钥'

const version = JSON.stringify({ open_id: 'XXXX', user_nick: '中文巴拉!@#$%^&*()_+~`./' })
console.log('原文 version', version)

console.log('1 - AES加密, 将json变成加密后的密文字符串')
const encryptContent = aesUtil.encrypt(version, key)
console.log('encryptContent', encryptContent)

console.log(
  '2 - url encode, get请求需要在url中传参, 将base64字符串的等号等url不支持的字符进行转义. post 请求可以省略这一步'
)
const urlParameter = encodeURIComponent(encryptContent)
console.log('urlParameter', urlParameter)

console.log('\n=== 解密过程与加密完全相反,以下代码仅做验证测试,实际客户端无需用到 ===\n')
console.log('1. url decode')
const encryptContent2 = decodeURIComponent(urlParameter)
console.log(encryptContent2)

console.log('2. aes解密')
const version2 = aesUtil.decrypt(encryptContent2, key)
console.log(version2)
